﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Data;

namespace DAO
{
    public class Provider
    {
        public static SqlConnection ConnectDB()
        {
            string _str = @"Initial Catalog=db_NLMT;Data Source=.\SQLExpress;Integrated Security=SSPI;";
            //string _str = @"Data Source=.\SQLEXPRESS;AttachDbFilename=" + @"|DataDirectory|db_NLMT.mdf" + ";Integrated Security=SSPI;User Instance=True";
            SqlConnection conn = new SqlConnection(_str);
            conn.Open();
            return conn;

        }
        public static bool IsNumber(string pText)
        {
            Regex regex = new Regex(@"^[-+]?[0-9]*\.?[0-9]+$");
            return regex.IsMatch(pText);
        }

        public static DataTable TimKiem(string sql)
        {
            SqlConnection _cn = Provider.ConnectDB();
            SqlDataAdapter _apt = new SqlDataAdapter(sql, _cn);
            DataTable _tb = new DataTable();
            _apt.Fill(_tb);
            _cn.Close();
            return _tb;
        }
    }
}
